import { defHttp } from '@/utils/http/axios';
import {
  Article,
  ArticleListResultModel,
  Category,
  Movie,
  MovieAdd,
  MovieListResultModel,
  MovieUpdate,
} from './model/tableModel';

enum Api {
  ARTICLE_API = '/articles',
  CATEGORY = '/categories',
  MOVIE_API = '/movies',
  CARE_SITE = '/caresites',
}

type APIParams = {
  pageSize: number;
  page?: number;
  sortField?: string;
  sortOrder?: number;
  [key: string]: any;
};

export const getAritcleListApi = (params: APIParams) =>
  defHttp.get<ArticleListResultModel>({ url: Api.ARTICLE_API, params });

export const getAritcleApi = (id: number) =>
  defHttp.get<Article>({ url: Api.ARTICLE_API + '/' + id, params: { id } });

export const delAritcleApi = () => defHttp.delete<void>({ url: Api.ARTICLE_API });

export const updateAritcleApi = (id: number, params: Article) =>
  defHttp.put<void>({ url: Api.ARTICLE_API + '/' + id, params });

export const addAritcleApi = (params: Article) =>
  defHttp.post<void>({ url: Api.ARTICLE_API, params });

export const getMovieListApi = (params: APIParams) =>
  defHttp.get<MovieListResultModel>({ url: Api.MOVIE_API, params });

export const movieAddApi = (params: MovieAdd) =>
  defHttp.post<void>({ url: Api.MOVIE_API + '/add', params });

export const movieUpdateApi = (id: number, params: MovieUpdate) =>
  defHttp.put<void>({ url: Api.MOVIE_API + '/update/' + id, params });

export const getMovieApi = (id: number) => defHttp.get<Movie>({ url: Api.MOVIE_API + '/' + id });

export const deleteMovieApi = (id: number) =>
  defHttp.delete<void>({ url: Api.MOVIE_API + '/delete/' + id });

export const getCareSiteListApi = (params: APIParams) =>
  defHttp.get<ArticleListResultModel>({ url: Api.CARE_SITE, params });

export const getCareSiteViewListApi = (params: APIParams) =>
  defHttp.get<ArticleListResultModel>({ url: Api.CARE_SITE + '/view', params });

export const careSiteAddApi = (params: { title: string; url: string }) =>
  defHttp.post<ArticleListResultModel>({ url: Api.CARE_SITE, params });

export const careSiteUpdateApi = (params: { id: number; title: string; url: string }) =>
  defHttp.put<ArticleListResultModel>({ url: Api.CARE_SITE, params });

export const getCategoryListApi = () =>
  defHttp.get<Category[]>({ url: Api.ARTICLE_API + Api.CATEGORY });

export const getCareDetailApi = Api.CARE_SITE;
